package com.gbr.application.model;

import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

import com.ng.framework.model.DefaultModel;

public class Capture extends DefaultModel {
    private List<Frame> frames = new ArrayList<>();
    private Rectangle   rect;

    public Capture(String name, Rectangle r) {
        super(name);
        this.setRect(r);
    }

    protected Capture(Capture other) {
        this(other.getId(), other.getRect());
    }

    public void addFrame(BufferedImage img, int delay) {
        frames.add(new Frame(img, delay));
    }

    public void clearFrames() {
        frames.clear();
    }

    public List<Frame> getFrames() {
        return frames;
    }

    public Rectangle getRect() {
        return rect;
    }

    public void setRect(Rectangle rect) {
        this.rect = rect;
    }

    @Override
    public String toString() {
        return getId();
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + ((frames == null) ? 0 : frames.hashCode());
        result = prime * result + ((rect == null) ? 0 : rect.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (!super.equals(obj))
            return false;
        if (getClass() != obj.getClass())
            return false;
        Capture other = (Capture) obj;
        if (frames == null) {
            if (other.frames != null)
                return false;
        } else if (!frames.equals(other.frames))
            return false;
        if (rect == null) {
            if (other.rect != null)
                return false;
        } else if (!rect.equals(other.rect))
            return false;
        return true;
    }
}
